package com.ruoyi.slope.warning.pushRecord.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.slope.dataFile.domain.SlopeDataFile;
import com.ruoyi.slope.dataFile.service.ISlopeDataFileService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.slope.warning.pushRecord.domain.SlopeWarningPushrecord;
import com.ruoyi.slope.warning.pushRecord.service.ISlopeWarningPushrecordService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 推送记录Controller
 * 
 * @author psy
 * @date 2025-04-27
 */
@RestController
@RequestMapping("/warning/pushrecord")
public class SlopeWarningPushrecordController extends BaseController
{    
    @Autowired
    private ISlopeDataFileService slopeDataFileService;
    @Autowired
    private ISlopeWarningPushrecordService slopeWarningPushrecordService;

    /**
     * 查询推送记录列表
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:list')")
    @GetMapping("/list")
    public TableDataInfo list(SlopeWarningPushrecord slopeWarningPushrecord)
    {
        startPage();
        List<SlopeWarningPushrecord> list = slopeWarningPushrecordService.selectSlopeWarningPushrecordList(slopeWarningPushrecord);
        return getDataTable(list);
    }

    /**
     * 导出推送记录列表
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:export')")
    @Log(title = "推送记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SlopeWarningPushrecord slopeWarningPushrecord)
    {
        List<SlopeWarningPushrecord> list = slopeWarningPushrecordService.selectSlopeWarningPushrecordList(slopeWarningPushrecord);
        ExcelUtil<SlopeWarningPushrecord> util = new ExcelUtil<SlopeWarningPushrecord>(SlopeWarningPushrecord.class);
        String path = util.exportExcel(response, list, "推送记录数据"); 
        SlopeDataFile slopeDataFile = new SlopeDataFile();
        slopeDataFile.setFileName(path);
        slopeDataFileService.insertSlopeDataFile(slopeDataFile);
    }

    /**
     * 获取推送记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(slopeWarningPushrecordService.selectSlopeWarningPushrecordById(id));
    }

    /**
     * 新增推送记录
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:add')")
    @Log(title = "推送记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SlopeWarningPushrecord slopeWarningPushrecord)
    {
        return toAjax(slopeWarningPushrecordService.insertSlopeWarningPushrecord(slopeWarningPushrecord));
    }

    /**
     * 修改推送记录
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:edit')")
    @Log(title = "推送记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SlopeWarningPushrecord slopeWarningPushrecord)
    {
        return toAjax(slopeWarningPushrecordService.updateSlopeWarningPushrecord(slopeWarningPushrecord));
    }

    /**
     * 删除推送记录
     */
    @PreAuthorize("@ss.hasPermi('warning:pushrecord:remove')")
    @Log(title = "推送记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(slopeWarningPushrecordService.deleteSlopeWarningPushrecordByIds(ids));
    }
}
